package com.ram.controller;

import com.ram.pojo.Building;
import com.ram.pojo.BuildingDTO;
import com.ram.pojo.BuildingVO;
import com.ram.pojo.PageResult;
import com.ram.pojo.Result;
import com.ram.service.BuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/building")
public class BuildingController {
    @Autowired
    private BuildingService buildingService;

    @GetMapping("/list")
    public Result list() {
        return Result.success(buildingService.list());
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(buildingService.getById(id));
    }

    @PostMapping
    public Result add(@RequestBody Building building) {
        buildingService.add(building);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Building building) {
        buildingService.update(building);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        buildingService.deleteById(id);
        return Result.success();
    }

    // 分页+条件查询
    @PostMapping("/page")
    public Result pageQuery(@RequestBody BuildingDTO dto) {
        PageResult<BuildingVO> pageResult = buildingService.pageQuery(dto);
        return Result.success(pageResult);
    }
} 